﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}

<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>
<!DOCTYPE html>
<html>
@* <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="//unpkg.com/layui@2.9.18/dist/css/layui.css" rel="stylesheet">
</head> *@
<body>

    <form class="layui-form" action="">
        <div class="layui-form-item">
            <div class="layui-form-item">

                <div class="layui-inline">
                    <div class="layui-inline">
                        <label class="layui-form-label">采购日期：</label>
                        <div class="layui-input-inline layui-input-wrap">
                            <input type="date" id="purchaseTime" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">羊只类型</label>
                        <div class="layui-input-block">
                            <select name="city" id="sheepType" lay-filter="testSelect">
                                <option value="0">请选择</option>
                                <option value="1">公羊</option>
                                <option value="2">母羊</option>
                                <option value="3">小羊</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">仓库</label>
                        <div class="layui-input-block">
                            <select name="city" id="wareHouse" lay-filter="testSelect1">
                                <option value="">请选择</option>
                                <option value="北京">北京</option>
                                <option value="天津">天津</option>
                                <option value="上海">上海</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">栋舍</label>
                        <div class="layui-input-block">
                            <select name="city" id="cottageId" lay-filter="testSelect2">
                                <option value="0">请选择</option>
                                <option value="1">北京</option>
                                <option value="2">天津</option>
                                <option value="3">上海</option>
                            </select>
                        </div>
                    </div>

                    <label class="layui-form-label">批次/耳号：</label>
                    <div class="layui-input-inline layui-input-wrap">
                        <input type="date" id="recordAuricle" class="layui-input">
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">采购员</label>
                        <div class="layui-input-block">
                            <select name="city" id="purchaseName" lay-filter="testSelect3">
                                <option value="">请选择</option>
                                <option value="张三">张三</option>
                                <option value="李四">李四</option>
                                <option value="王五">王五</option>
                            </select>
                        </div>
                    </div>

                    <label class="layui-form-label">单据号：</label>
                    <div class="layui-input-inline layui-input-wrap">
                        <input type="text" id="prchaseNumber" class="layui-input">
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">供应商</label>
                        <div class="layui-input-block">
                            <select name="city" id="vendorId" lay-filter="testSelect4">
                                <option value="0">请选择</option>
                                <option value="1">张三</option>
                                <option value="2">李四</option>
                                <option value="3">王五</option>
                            </select>
                        </div>
                    </div>

                </div>
                <button type="button" class="layui-btn layui-bg-red" id="searchBtn" onclick="Show()">搜索</button>

                <button type="button" class="layui-btn layui-bg-red" onclick="Add()" lay-on="test-iframe-curl">新增</button>

            </div>


        </div>



       
        <table class="layui-table">
            <thead>
                <tr>
                    <td>序号</td>
                    <td>单据号</td>
                    <td>采购日期</td>
                    <td>核算单元</td>
                    <td>类别</td>
                    <td>供应商</td>
                    <td>摘要</td>
                    <td>批次/耳号</td>
                    <td>栋舍</td>
                    <td>转入栏位</td>
                    <td>性别</td>
                    <td>阶段</td>
                    <td>采购员</td>
                    <td>仓库</td>
                    <td>商品名称</td>
                    <td>入库数量</td>
                    <td>调整数量</td>
                    <td>结算数量</td>
                    <td>只均单价（元）</td>
                    <td>金额</td>
                    <td>单位折扣</td>
                    <td>结算金额</td>
                    <td>创建人</td>
                    <td>创建时间</td>
                    <td>修改人</td>
                    <td>修改时间</td>
                    <td>审核人</td>
                    <td>审核时间</td>
                    <td>修改人</td>
                </tr>
            </thead>
            <tbody></tbody>
        </table>
        <div id="demo-laypage-all"></div>
    </form>


    <!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
    <script src="//unpkg.com/layui@2.9.18/dist/layui.js"></script>
    <script>
        function Add() {
            location.href = "/Purchase/AddPurchaseIndex";
        }
        layui.use('form', function () {
            var table = layui.table;
            var form = layui.form;
            var layer = layui.layer;
            var laypage = layui.laypage;
            var pageIndex = 1;
            var pageSize = 5;


            form.on('select(testSelect)', function (data) {
                Show(data.value); // data.value 返回选中的值
            });
            form.on('select(testSelect1)', function (data) {
                Show(data.value); // data.value 返回选中的值
            });
            form.on('select(testSelect2)', function (data) {
                Show(data.value); // data.value 返回选中的值
            });
            form.on('select(testSelect3)', function (data) {
                Show(data.value); // data.value 返回选中的值
            });
            form.on('select(testSelect4)', function (data) {
                Show(data.value); // data.value 返回选中的值
            });





            Show();


            //角色显示列表
            function Show() {
                var purchaseTime = null
                var purchaseName = $("#purchaseName").val()
                var sheepType = $("#sheepType").val()
                var cottageId = $("#cottageId").val()
                var recordAuricle = $("#recordAuricle").val()
                var prchaseNumber = $("#prchaseNumber").val()
                var vendorId = $("#vendorId").val()
                var wareHouse = $("#wareHouse").val()
                $.post({
                    url: 'http://localhost:5269/api/SheepPurchase/GetPurchase',
                    data: JSON.stringify({ purchaseTime: purchaseTime, purchaseName: purchaseName, sheepType: sheepType, cottageId: cottageId, recordAuricle: recordAuricle, prchaseNumber: prchaseNumber, vendorId: vendorId, wareHouse: wareHouse, pageIndex: pageIndex, pageSize: pageSize }),
                    async: false,
                    dataType: "json",
                    contentType: "application/json",
                    success: res => {
                        var count = "";

                        $.each(res.data, function () {
                            count += `
                                                <tr>
                                                        <td>${this.purchaseId}</td>
                                                        <td>${this.purchaseName}</td>
                                                        <td>${this.purchaseTime}</td>
                                                        <td>${this.sheepType}</td>
                                                        <td>${this.purchaseCategory}</td>
                                                        <td>${this.accountingUnit}</td>
                                                        <td>${this.vendorId}</td>
                                                        <td>${this.abstract}</td>
                                                        <td>${this.prchaseNumber}</td>
                                                        <td>${this.recordAuricle}</td>
                                                        <td>${this.cottageId}</td>
                                                        <td>${this.field}</td>
                                                        <td>${this.sex}</td>
                                                        <td>${this.goodName}</td>
                                                        <td>${this.package}</td>
                                                        <td>${this.measurement}</td>
                                                        <td>${this.storage}</td>
                                                        <td>${this.purchasePrice}</td>
                                                        <td>${this.purchaseNumPrice}</td>
                                                        <td>${this.purchaseDiscount}</td>
                                                        <td>${this.purchaseAdjust}</td>
                                                        <td>${this.purchaseSettle}</td>
                                                        <td>${this.purchaseWeight}</td>
                                                        <td>${this.wareHouse}</td>

                                                    <td>
                                                            <a onclick="funDel()" class="btn btn-link">删除</a>
                                                                    <a onclick="funDel()" class="btn btn-link" lay-on="test-iframe-curl">编辑</a>
                                                    </td>
                                                </tr>
                                                `
                        })
                        //pagedCount = res.pagedCount;
                        //pcount = res.totalCount;
                        $("tbody").html(count)
                        // console.log(res.data)

                        //var page = Math.ceil(res.totalCount / 5);  //总页数
                        console.log(996, pageSize, pageIndex, res);
                        // 完整显示
                        laypage.render({
                            elem: 'demo-laypage-all', // 元素 id
                            curr: pageIndex,//当前页
                            pages: res.pagedCount,    //总页数
                            limit: pageSize,//每页几条
                            limits: [5, 10, 15],
                            count: res.totalCount, // 数据总数
                            layout: ['count', 'prev', 'page', 'first', 'last', 'next', 'limit', 'skip'], // 功能布局
                            jump: function (obj, first) {
                                if (!first) {
                                    console.log(888, obj);
                                    console.log(obj.curr); // 得到当前页，以便向服务端请求对应页的数据。
                                    console.log(obj.limit); // 得到每页显示的条数
                                    pageIndex = obj.curr;
                                    pageSize = obj.limit;
                                    Show();
                                }
                            }
                        });
                    }
                })


            }

        });

    </script>


</body>

</html>